package com.docker.apps.afterservice.ui;

import android.arch.lifecycle.ViewModelProviders;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.docker.apps.R;
import com.docker.apps.afterservice.vm.AfterServiceViewModel;
import com.docker.apps.databinding.ProAfterServiceEditLogisticsActivityBinding;
import com.docker.common.common.router.AppRouter;
import com.docker.common.common.ui.base.NitCommonActivity;
import com.docker.common.common.utils.cache.CacheUtils;
import com.docker.common.common.utils.rxbus.RxBus;
import com.docker.common.common.utils.rxbus.RxEvent;
import com.docker.common.common.vo.UserInfoVo;

import java.util.HashMap;

/**
 * kxf -> 2020-02-18
 **/
@Route(path = AppRouter.ORDER_AFTER_EDIT_WULIU)
public class AfterServiceEditLogisticsActivity extends NitCommonActivity<AfterServiceViewModel, ProAfterServiceEditLogisticsActivityBinding> {

    @Override
    public void initView() {
        mToolbar.setTitle("填写退换货物流");
        String refundsNo = getIntent().getStringExtra("refundsNo");
        mBinding.editOk.setOnClickListener(v -> {
            String com = mBinding.editCom.getText().toString();
            String num = mBinding.editNum.getText().toString();
            UserInfoVo userInfoVo = CacheUtils.getUser();
            HashMap<String, String> params = new HashMap<>();
            params.put("memberid", userInfoVo.uid);
            params.put("uuid", userInfoVo.uuid);
            params.put("refundsNo", refundsNo);
            params.put("logisticsNo", num);
            params.put("logistic", com);
            mViewModel.returnLogistcs(params);

        });

    }

    @Override
    public void initObserver() {

        mViewModel.mServerLiveData.observe(this, o -> {
            RxBus.getDefault().post(new RxEvent<>("updateAfterService", 1));
            finish();
        });

    }

    @Override
    public void initRouter() {
        ARouter.getInstance().inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.pro_after_service_edit_logistics_activity;
    }

    @Override
    public AfterServiceViewModel getmViewModel() {
        return ViewModelProviders.of(this, factory).get(AfterServiceViewModel.class);
    }
}